<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"
    import = "ass.beans.*"
	import = "ass.dao.*"
	import = "ass.dao.support.*"
	import = "java.util.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>View User Profile</title>
</head>
<body>
	<%@ include file="header.html"%>
	<%@ include file="userNavBar.html"%>
	
	<% 
	
	String username = (String) request.getParameter("username");
	UserDAO userDAO = new UserDAOImpl();
	UserBean userBean = userDAO.getUser(username);

	UserPrivacyDAO userPrivacyDAO= new UserPrivacyDAOImpl();
	UserPrivacyBean userPrivacy = userPrivacyDAO.getUser(username);
	
	String usernameOwner = (String) session.getAttribute("username");
	UserFriendsDAO userFriendsDAO = new UserFriendsDAOImpl();
	UserFriendsBean userFriendsBean = userFriendsDAO.getUserFriendRow(usernameOwner, username);
	UserFriendsBean userFriendsBean2 = userFriendsDAO.getUserFriendRow(username, usernameOwner);
	
	if (userPrivacy == null){
		userPrivacy = new UserPrivacyBean();
		userPrivacy.setEmailShared(false);
		userPrivacy.setFavActorShared(false);
		userPrivacy.setFavGenreShared(false);
		userPrivacy.setYearOfBirthShared(false);
	}
	
	boolean is_friend = false;
	if (userFriendsBean != null){
		if (userFriendsBean.isAccepted()){
			is_friend = true;
		}
	}
	
	if (userFriendsBean2 != null){
		if (userFriendsBean2.isAccepted()){
			is_friend = true;
		}
	}
	
	
	%>
	
	

	<div align="center">
	
	<%= (String) request.getAttribute("friend_confirm") == null ? "":(String) request.getAttribute("friend_confirm") %>
		
		<form name="form1" method="post" action="SubmitFriendRequest">
			<input type="hidden" name="username" value="<%=userBean.getUsername()%>" />
			<input type="hidden" name="email" value="<%=userBean.getEmail()%>" />
			<table width="400" border="0">
			<%	
			out.print("<tr>");
			out.print("	<td align='left'>Username:</td>");
			out.print("	<td align='left'>"+userBean.getUsername()+"</td>");
			out.print("</tr>");
			out.print("<tr>");
			out.print("	<td align='left'>First name:</td>");
			out.print("	<td align='left'>"+userBean.getFirst_name()+"</td>");
			out.print("</tr>");
			out.print("<tr>");
			out.print("<td align='left'>Last name:</td>");
			out.print("	<td align='left'>"+userBean.getLast_name()+"</td>");
			out.print("</tr>");
			out.print("<tr>");
			if (userPrivacy.isYearOfBirthShared() || is_friend){
			out.print("<td align='left'>Year of birth:</td>");
			out.print("	<td align='left'>"+userBean.getYear_of_birth()+"</td>");
			out.print("</tr>");
			}
			if (userPrivacy.isEmailShared() || is_friend){
		    out.print("<tr>");
		    out.print("<td align='left'>Email:</td>");
		    out.print("	<td align='left'>"+userBean.getEmail()+"</td>");
		    out.print("</tr>");
			}
		    if (userPrivacy.isFavActorShared() || is_friend){
		    out.print("<tr>");
		    out.print("<td align='left'>Favorite Actors and Actress:</td>");
		    out.print("	<td align='left'>"+userBean.getFavourite_actors()+"</td>");
		    out.print("</tr>");
		    }
		    if (userPrivacy.isFavGenreShared() ||is_friend){
		    out.print("<tr>");
		    out.print("<td align='left'>Favorite Genre:</td>");
		    out.print("	<td align='left'>"+userBean.getFavourite_genre()+"</td>");
		    out.print("</tr>");
		    }
		    
			 %>
			 </table>
			 
		<% if (userFriendsBean == null && userFriendsBean2 == null) { %>	 
		<table width="400" border="0">
		<tr>
		<td>Leave message for this user:</td>
		<td><textarea name="message"></textarea></td>
		</tr>
		<tr>
		<td>Send the request</td>
		<td><input type="submit" value="Submit"> </td>
		</tr>
		</table>
			 
		<% } 
		
		if (userFriendsBean == null && userFriendsBean2 != null) {
			out.println("<br><br>Your friend have invited you");
		}else if (userFriendsBean != null && userFriendsBean2 == null){
			out.println("<br><br>Your has sent your invitation");
		}
		
		%>
		</form>
	</div>

</body>
</html>


</body>
</html>